const express = require('express');
const router = express.Router();
const Result = require('../app/Result')

const areaService = require('../service/area')



const getRoots = async (req,res) =>{
    console.log('get roots')
    let rows = await areaService.queryRootArea()
    let items = []
    rows.forEach(row => {
        items.push({label:row.name, value: row.id})
    });
        res.json(items)
}
    


const getChildrenByRootId = async (req,res) =>{
    var pid =  req.query.pid || req.body.pid ;
    console.log(pid);
    let rows = await areaService.queryArarByPid(pid);

    let items = []
    rows.forEach(row => {
        items.push({label:row.name, value: row.id})
    });
    res.json(items)
}




router.post('/area/getrootlist', getRoots )
router.post('/area/getchildrenbyrootid', getChildrenByRootId)


module.exports = router